package com.example.coursemgt.dao;

import com.example.coursemgt.model.Course;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CourseDao {

    //用户列表
    @Select("select * from course")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "teacherId", column = "teacherId"),
            @Result(property = "schoolId", column = "schoolId")
    })
    List<Course> queryAll();

    //根据id获取course
    @Select("select * from course where id =#{id}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "teacherId", column = "teacherId"),
            @Result(property = "schoolId", column = "schoolId")
    })
    Course findCourseById(Long id);

    //根据id修改course
    @Update("update course set name=#{name},score=#{score},teacherId=#{teacherId},schoolId=#{schoolId} WHERE id = #{id} ")
    int updateCourse(Course course);

    //根据id删除用户
    @Delete("delete from course where id = #{id}")
    int deleteCourseById(Long id);

    @Insert("insert into course (name, teacherId,schoolId) values(#{name},#{teacherId},#{schoolId})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void saveCourse(Course course);

    @Select("select * from course order by (teacherid+schoolid) DESC limit 10")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "teacherId", column = "teacherId"),
            @Result(property = "schoolId", column = "schoolId")
    })
    List<Course> top();
}
